const {
  $util,
} = getApp();
Page({
  data: {
    page: 1,
    list: [],
    isloadmore: true,
  },
  onLoad(ops) {
    wx.setNavigationBarTitle({
      title: ops.barTitle && decodeURIComponent(ops.barTitle) || '关系转接',
    }); 
  },
  onShow() {
    this.setData({
      page: 1,
    }, () => {
      this.loadList();
    });
    let wxData = wx.getStorageSync('qyUserInfo') || {};
    this.setData(wxData);
    this.setData({
      isSaaS: wx.getStorageSync('isSaaS'),
    })
  },
  loadList() {
    const {
      page,
      list: d_list,
    } = this.data;
    $util.request({
      url: 'entry/wxapp/edu.change.main',
      data: {
        page,
      },
      success: (res) => {
        let list = res.list;
        if (page > 1) {
          list = [...d_list, ...list];
        }
        this.setData({
          list,
          canshow: res.canshow,
          isloadmore: res.list.length > 0,
          loaded: true,
          canadd: res.canadd,
        });
      },
    });
  },
  onReachBottom() {
    if (!this.data.isloadmore) return;
    this.setData({
      page: this.data.page + 1,
    }, () => {
      this.loadList();
    });
  },
});
